import { login } from '@/api/user'

const state = () => ({
  userInfo: null // 用户信息
})

const mutations = {
  SET_USER_INFO(state, userInfo) {
    state.userInfo = userInfo
  }
}

const actions = {
  async handleLogin({ commit }, { userName }) {
    userName = userName.trim()
    const { data } = await login({ userName })
    commit('SET_USER_INFO', data)
  }
}

export default {
  namespaced: true, // 开启命名空间
  state,
  mutations,
  actions
}
